/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package CustomerGUIs;


import Model.Customer;
import Model.InternalDBManager;
import Supermarket.AppMessages;
import java.util.Random;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.swing.ImageIcon;

/**
 *
 * @author Manolis
 */
public class EditCustomerForm extends javax.swing.JDialog {
    
    private Customer customer;
    private boolean statusUpdate = false;
    private static EntityManager em;
    
    /**
     * Creates new form EditCustomerForm
     */
    public EditCustomerForm(java.awt.Frame parent, boolean modal, Customer customer) {
        super(parent, modal);
        em = InternalDBManager.getEm();
        this.customer = customer;
        this.setIconImage(new
                ImageIcon(getClass().getResource("..\\Images\\cart.png")).getImage());
        initComponents();
        //γεμίζει τα πεδία της φόρμας με τα στοιχεία του πελάτη
        setLabelsFromCustomer();
        
    }
    
     public EditCustomerForm(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.setIconImage(new
                ImageIcon(getClass().getResource("..\\Images\\cart.png")).getImage());
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        FirstNameField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        LastNameField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        AddressField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        PointsCardLabel = new javax.swing.JLabel();
        PasswordField = new javax.swing.JTextField();
        PasswordMissingLabel = new javax.swing.JLabel();
        LastNameMissingLabel = new javax.swing.JLabel();
        FirstNameMissingLabel = new javax.swing.JLabel();
        RegisterButton = new javax.swing.JButton();
        CancelButton = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        ErrorMessageLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Τροποποίηση Στοιχείων Πελατών");

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        FirstNameField.setColumns(30);
        FirstNameField.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        FirstNameField.setToolTipText("");
        FirstNameField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FirstNameFieldActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setText("Όνομα:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel2.setText("Επώνυμο:");

        LastNameField.setColumns(10);
        LastNameField.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Διεύθυνση:");

        AddressField.setColumns(50);
        AddressField.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("Αριθμός κάρτας πόντων:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel5.setText("Password:");

        jPanel2.setBackground(new java.awt.Color(204, 204, 204));
        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));

        PointsCardLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        PointsCardLabel.setForeground(new java.awt.Color(0, 0, 153));
        PointsCardLabel.setText("XXX-XXX");
        PointsCardLabel.setToolTipText("");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(PointsCardLabel)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(PointsCardLabel))
        );

        PasswordField.setColumns(20);
        PasswordField.setToolTipText("");

        PasswordMissingLabel.setForeground(java.awt.Color.red);
        PasswordMissingLabel.setText("    ");
        PasswordMissingLabel.setToolTipText("");

        LastNameMissingLabel.setForeground(java.awt.Color.red);
        LastNameMissingLabel.setText("    ");
        LastNameMissingLabel.setToolTipText("");

        FirstNameMissingLabel.setForeground(java.awt.Color.red);
        FirstNameMissingLabel.setText("    ");
        FirstNameMissingLabel.setToolTipText("");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(AddressField, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(30, 30, 30)
                                .addComponent(PasswordMissingLabel)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(FirstNameField, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(FirstNameMissingLabel)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(LastNameField, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(LastNameMissingLabel)))
                        .addContainerGap(18, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(FirstNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(LastNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LastNameMissingLabel)
                    .addComponent(FirstNameMissingLabel))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(AddressField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(PasswordMissingLabel))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        RegisterButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        RegisterButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/save_16.png"))); // NOI18N
        RegisterButton.setText("Καταχώρηση");
        RegisterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RegisterButtonActionPerformed(evt);
            }
        });

        CancelButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        CancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/cancel_16.png"))); // NOI18N
        CancelButton.setText("Ακύρωση");
        CancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelButtonActionPerformed(evt);
            }
        });

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/supermarket_320.png"))); // NOI18N

        ErrorMessageLabel.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        ErrorMessageLabel.setForeground(new java.awt.Color(255, 0, 0));
        ErrorMessageLabel.setToolTipText("");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(ErrorMessageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 339, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(RegisterButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(CancelButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(135, 135, 135)
                .addComponent(ErrorMessageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(RegisterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel10))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(15, 15, 15)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(94, Short.MAX_VALUE)))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void FirstNameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FirstNameFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FirstNameFieldActionPerformed

    private void RegisterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RegisterButtonActionPerformed
        //Σβήνουμε τυχόν μηνύματα λάθους (labels)
        initLabels();
        //αν η μεταφορά και αποθήκευση έγινε κανονικά κλείσιμο της φόρμας
        if(statusUpdate = DataManager()){
            this.dispose();
        }
    }//GEN-LAST:event_RegisterButtonActionPerformed

    private void CancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_CancelButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EditCustomerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EditCustomerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EditCustomerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EditCustomerForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                EditCustomerForm dialog = new EditCustomerForm(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField AddressField;
    private javax.swing.JButton CancelButton;
    private javax.swing.JLabel ErrorMessageLabel;
    private javax.swing.JTextField FirstNameField;
    private javax.swing.JLabel FirstNameMissingLabel;
    private javax.swing.JTextField LastNameField;
    private javax.swing.JLabel LastNameMissingLabel;
    private javax.swing.JTextField PasswordField;
    private javax.swing.JLabel PasswordMissingLabel;
    private javax.swing.JLabel PointsCardLabel;
    private javax.swing.JButton RegisterButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
    //μέθοδος που αναλαμβάνει να αποθηκεύσει τα δεδομένα της φόρμας
    
    public boolean DataManager(){
        //αν τα στοιχεία του πελάτη δεν είναι στη σωστή μορφή επιστροφή
        if(!registerCustomer()){
            return false;  
        //αλλιώς αποθηκεύσε τον πελάτη
        }else if (AddCustomerToDB()){
                    return true; 
        } 
        return false;
    }
    
    
    //έλεγχος και μεταφορά των πεδίων της φόρμας σε αντικείμενο customer
    //για την καταχώρηση στη βάση.
    public boolean registerCustomer(){
        boolean success = true;
         
        //Έλεγχος εισαγωγής ονόματος πελάτη
        if(FirstNameField.getText().isEmpty()){
            ErrorMessageLabel.setText(AppMessages.FieldsMissingMsg);
            FirstNameMissingLabel.setText("(*)");
            success = false;
        }else{
            customer.setFirstName(FirstNameField.getText());   
        }
        //Έλεγχος εισαγωγής επώνυμου πελάτη
        if(LastNameField.getText().isEmpty()){
            ErrorMessageLabel.setText(AppMessages.FieldsMissingMsg);
           LastNameMissingLabel.setText("(*)");
            success = false;
        }else{
            customer.setLastName(LastNameField.getText());   
        }
         if(AddressField.getText().isEmpty()){
            customer.setAddress(null);
        }else{
            customer.setAddress(AddressField.getText());   
        }
        //Έλεγχος εισαγωγής κωδικού πελάτη
         if(PasswordField.getText().isEmpty()){
            ErrorMessageLabel.setText(AppMessages.FieldsMissingMsg);
            PasswordMissingLabel.setText("(*)");
            success = false;
        }else{
            customer.setPassword(PasswordField.getText());   
        }
        customer.setPointsCardNumber(PointsCardLabel.getText());
        customer.setAvailablePoints(0);
        //επέστρεψε το αποτέλεσμα της μεταφοράς δεδομένων
        return success;
    }
    
    //δημιουργία αριθμού κάρτας πόντων
    public String makeCardNumber(){
        //έναρξη δοσοληψιών
       if (!em.getTransaction().isActive()){
                em.getTransaction().begin();
            }
       //ένα string για τον αριθμό κάρτας πόντων
        String cardNumber;
        //όσο ο αριθμός θα εντοπίζεται στη ΒΔ
        while(true){
            //Δημιουργία αριθμού κάρτας
            Random rn = new Random();
            cardNumber = ""+rn.nextInt(9)+ rn.nextInt(10) + rn.nextInt(10) + "-" 
                    + rn.nextInt(10) + rn.nextInt(10) + rn.nextInt(10);
            try{
                //έλεγχος ύπαρξης κάρτας στη ΒΔ
                Customer customers_card = (Customer) em.createNamedQuery("Customer.findByPointsCardNumber")
                .setParameter("pointsCardNumber", cardNumber).getSingleResult();
                //αν η λίστα είναι κενή - δεν έχει βρεθεί ο αριθμός κάρτας
            }catch(NoResultException e){
                    break;
            }
        }
        return cardNumber;
    }
    
    
    //μέθοδος απόδοσης τιμής στο πεδίο αριθμού κάρτας πόντων
    public void setPointsCardLabel(String pointsCardNumber){
        PointsCardLabel.setText(pointsCardNumber);
    }
    
    //Πρόσθήκη πελάτη στη ΒΔ
    private boolean AddCustomerToDB() {
        try {
             if (!em.getTransaction().isActive()){
                em.getTransaction().begin();
            }
            em.persist(customer);            
            em.getTransaction().commit();
            //Εμφανίζει μήνυμα επιτυχίας 
            AppMessages.SuccessMessage(this);
            return true;
        } catch (SecurityException e) {
            AppMessages.FailureMessage(this, e);
            em.getTransaction().rollback();
            return false;
        }
    }
    
     
    

    
    //μέθοδος που αρχικοποιεί όλα τα labels που χρησιμοποιούνται
    //για την εμφάνιση μηνυμάτων
    private void initLabels() {
        ErrorMessageLabel.setText("");
        FirstNameMissingLabel.setText("");
        LastNameMissingLabel.setText("");
        PasswordMissingLabel.setText("");
    }

    //επιστρέφει το αποτέλεσμα της ενημέρωσης 
    public boolean getStatusUpdate() {
        return this.statusUpdate;
    }

    //μεταφέρει τα στοιχεία του πελάτη στα πεδία της φόρμας
    private void setLabelsFromCustomer() {
        //μεταφέρονται τα στοιχεία του πελάτη που περάστηκε
        //σαν παράμετρος από τη λίστα στα πεδία της φόρμας
        FirstNameField.setText(customer.getFirstName());
        LastNameField.setText(customer.getLastName());
        AddressField.setText(customer.getAddress());
        PasswordField.setText(customer.getPassword());
        PointsCardLabel.setText(customer.getPointsCardNumber());
    }
}
